import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {
            String str=in.next();
            while(str.length()>1)
            {
                int ret=0;//111
                for(int i=0;i<str.length();i++)
                {
                    ret=ret+(str.charAt(i)-'0');
                }
                str=String.valueOf(ret);
            }
            System.out.println(str);
        }

    }
}